package com.tanxi521.afkreward.placeholder;

import com.tanxi521.afkreward.data.AFKRewardMapper;
import com.tanxi521.afkreward.pojo.PlayerAfk;
import com.tanxi521.afkreward.util.RewardUtil;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;

public class AfkPlaceHolder extends PlaceholderExpansion {

    @Override
    public String onPlaceholderRequest(Player p, String identifier) {
        if (p != null && identifier.startsWith("north_")) {
            return getPlaceHolder(p, identifier);
        }
        return "";
    }

    public static String getPlaceHolder(Player p, String identifier) {
        if (identifier.equals("north_afk_type")) {
            PlayerAfk playerAfk = AFKRewardMapper.AFK_MAP.get(p.getName());
            if (playerAfk != null) return playerAfk.getType() + "挂机";
            else return "未挂机";
        }
        if (identifier.equals("north_afk_reward")) {
            PlayerAfk playerAfk = AFKRewardMapper.AFK_MAP.get(p.getName());
            if (playerAfk != null) return playerAfk.getReward();
             else return "未挂机";
        }
        if (identifier.equals("north_afk_time")) {
            PlayerAfk playerAfk = AFKRewardMapper.AFK_MAP.get(p.getName());
            if (playerAfk != null) return RewardUtil.afkTime(playerAfk);
            else return RewardUtil.time(0);
        }
        if (identifier.equals("north_afk_total")) {
            PlayerAfk playerInfo = AFKRewardMapper.getPlayerInfo(p.getName());
            assert playerInfo != null;
            return RewardUtil.time(playerInfo.getTotal());
        }
        if (identifier.equals("north_afk_freq")) {
            PlayerAfk playerInfo = AFKRewardMapper.getPlayerInfo(p.getName());
            assert playerInfo != null;
            return playerInfo.getTimes() + "";
        }
        if (identifier.equals("north_afk_today")) {
            PlayerAfk playerInfo = AFKRewardMapper.getPlayerInfo(p.getName());
            assert playerInfo != null;
            return playerInfo.getToday() + "";
        }
        if (identifier.equals("north_afk_player")) {
            return AFKRewardMapper.AFK_MAP.size() + "";
        }
        return "";
    }

    @Override
    public String getIdentifier() {
        return "the";
    }

    @Override
    public String getAuthor() {
        return null;
    }

    @Override
    public String getVersion() {
        return null;
    }
}
